package com.example.splash;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

public class Lunb extends RecyclerView.Adapter<Lunb.Herodir> {

    public Lunb(Oikl itemClickListener, int[] asd) {
        this.itemClickListener = itemClickListener;
        this.asd = asd;
    }

    Oikl itemClickListener;
    private int[] asd;

    @NonNull
    @Override
    public Herodir onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View xiao = LayoutInflater.from(parent.getContext()).inflate(R.layout.lunb,parent,false);
        return new Herodir(xiao);
    }

    @Override
    public void onBindViewHolder(@NonNull Herodir holder, int position) {
    holder.imageView.setImageResource(this.asd[position]);
        int isVisible = View.INVISIBLE;
        if (getItemCount() == position + 1) {
            // 把按钮显示
            isVisible = View.VISIBLE;
        }
        holder.button.setVisibility(isVisible);
    }

    @Override
    public int getItemCount() {
        return asd.length;
    }

    public class Herodir extends RecyclerView.ViewHolder {
        ImageView imageView;
        Button button;
        public Herodir(@NonNull View itemView) {
            super(itemView);
            imageView = itemView.findViewById(R.id.imageView);
            button = itemView.findViewById(R.id.button);
            button.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    int position = getAdapterPosition();
                    itemClickListener.OnItemClick(position);
                }
            });
        }
    }
    interface Oikl{
        void OnItemClick(int position);
    }
}
